package com.example.venue_reservation_service.controller;

import com.example.venue_reservation_service.domain.Information;
import com.example.venue_reservation_service.domain.Price;
import com.example.venue_reservation_service.dto.*;
import com.example.venue_reservation_service.service.InformationService;
import com.example.venue_reservation_service.utils.QRCodeGenerator;
import com.example.venue_reservation_service.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@RestController
@RequestMapping("/information")
@Api("场地接口管理")
@CrossOrigin
public class InformationController {

    @Resource
    private InformationService informationService;

    @ApiOperation("获取所有场地的类型数据")
    @PostMapping("/type")
    public Result types(@RequestBody PageDTO dto){
        return informationService.getTypes(dto);
    }

    @ApiOperation("获取某个场馆内的所有场地数据")
    @GetMapping("/detail")
    public Result detail(@RequestParam("type_id") Integer typeId){
        return informationService.getDetails(typeId);
    }

    @ApiOperation("获取场地具体信息")
    @PostMapping("/query")
    public Result query(@RequestBody InformationDTO dto){
        return informationService.getInformation(dto);
    }

    @ApiOperation("获取场地的分类信息")
    @GetMapping("/types")
    public Result types(){
        return informationService.queryTypes();
    }

    @ApiOperation("添加场地信息")
    @PostMapping("/create")
    public Result create(@RequestBody Information information){
        return informationService.addInformation(information);
    }

    @ApiOperation("修改场地信息")
    @PostMapping("/update")
    public Result update(@RequestBody Information information){
        return informationService.updateInformation(information);
    }
    @ApiOperation("移除场地信息")
    @GetMapping("/remove")
    public Result remove(@RequestParam("id")Integer id){
        return informationService.delInformation(id);
    }

    @ApiOperation("修改场地价格")
    @PostMapping("/money")
    public Result money(@RequestBody Price price){
        return informationService.updatePrice(price);
    }

    @ApiOperation("获取场地分类")
    @PostMapping("/classify")
    public Result classify(@RequestBody TypeDTO dto){
        return informationService.classifyInformation(dto);
    }

    @ApiOperation("获取各个时间段下场地的可以使用的时间段")
    @PostMapping("/condition")
    public Result condition(@RequestBody QueryDTO dto){
        return informationService.getConditions(dto);
    }

    @ApiOperation("上传场地照片")
    @PostMapping("/img")
    public Result img(@RequestParam("id") Integer id,
                      @RequestParam("file") MultipartFile file){
        return informationService.upload(id, file);
    }

    @ApiOperation("管理员获取负责场馆中的场地的使用情况信息")
    @PostMapping("/admin")
    public Result admin(@RequestBody SQueryDTO dto){
        return informationService.adminMessage(dto);
    }

    @ApiOperation("管理员查看场地预约信息")
    @PostMapping("/view")
    public Result view(@RequestBody ViewDTO dto){
        return informationService.viewInformation(dto);
    }

    @ApiOperation("下载二维码图片")
    @GetMapping("/qr")
    public ResponseEntity<InputStreamResource> qr(@RequestParam("id") Integer id,
                                                  HttpServletResponse response){
        return informationService.QRDownload(id, response);
    }

}
